package com.travel.system.common.result;

import lombok.Data;

@Data
public class ResultInfo<T> {

    private int code;
    private String msg;
    private T data;

    public ResultInfo(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> ResultInfo<T> success(T data) {
        return new ResultInfo<T>(200, "操作成功", data);
    }

    public static <T> ResultInfo<T> success() {
        return new ResultInfo<T>(200, "操作成功", null);
    }

    public static <T> ResultInfo<T> fail(T data) {
        return new ResultInfo<T>(500, "操作失败", data);
    }

    public static <T> ResultInfo<T> fail() {
        return new ResultInfo<T>(500, "操作失败", null);
    }

    public static <T> ResultInfo<T> status(boolean boo) {
        if (boo) {
            return new ResultInfo<T>(200, "操作成功", null);
        }
        return new ResultInfo<T>(500, "操作失败", null);
    }


    public static ResultInfo<String> error(String msg) {
        return new ResultInfo<String>(500, msg, null);
    }

    public static ResultInfo<String> ok(String msg) {
        return new ResultInfo<String>(200, msg, null);
    }

}
